/*
 * This file is part of cnesreport.
 *
 * cnesreport is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * cnesreport is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with cnesreport.  If not, see <http://www.gnu.org/licenses/>.
 */

package fr.cnes.sonar.report.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Component {
    /**
     * ID in SonarQube
     */
    private String id;
    /**
     * Filename
     */
    private String name;
    /**
     * Path to the file
     */
    private String path;
    /**
     * List of metrics and their values the current file
     */
    private List<Measure> measures;

    /**
     * Default constructor
     */
    public Component() {
        this.id = "";
        this.name = "";
        this.path = "";
        this.measures = new ArrayList<>();
    }

    /**
     * Getter for the component's id
     * @return component's id
     */
    public String getId() {
        return id;
    }

    /**
     * Setter for the component's id
     * @param id component's id
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * Getter for the component's name
     * @return component's name
     */
    public String getName() {
        return name;
    }

    /**
     * Setter for the component's name
     * @param name component's name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Getter for the component's path
     * @return path to the file represented by the component
     */
    public String getPath() {
        return path;
    }

    /**
     * Setter for the component's path
     * @param path path to the file represented by the component
     */
    public void setPath(String path) {
        this.path = path;
    }

    /**
     * Getter for component's measures
     * @return list of measure realized on the component
     */
    public List<Measure> getMeasures() {
        return measures;
    }

    /**
     * Setter for component's measures
     * @param measures list of measure realized on the component
     */
    public void setMeasures(List<Measure> measures) {
        this.measures = measures;
    }

    /**
     * Overridden toString (generated by IntelliJ)
     * @return a string with all values setted.dai
     */
    @Override
    public String toString() {
        return "Component{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", path='" + path + '\'' +
                ", measures=" + measures +
                '}';
    }

    /**
     * toMap
     * @return the object as map containing general infos and metrics
     */
    public Map<String, String> toMap() {
        Map<String, String> map = new HashMap<>();
        map.put("ID", this.id);
        map.put("Name", this.name);
        map.put("Path", this.path);
        for(Measure m : measures){
            map.put(m.getMetric(), m.getValue());
        }
        return map;
    }
}
